n = int(input())
if 1000 <= n <= 9999:
    n1 = str (n//1000%10)
    n2 = str (n//100%10)
    n3 = str (n//10%10)
    n4 = str (n//1%10)
    spis = [int(n1), int(n2), int(n3), int(n4), int(n1 + n2), int(n2 + n3), int(n3 + n4), int(n1 + n2 + n3), int(n2 + n3 + n4), int(n1 + n2 + n3 + n4)]
    spis.sort()
    spis = spis[::-1]
    for x in spis:
        f = True
        for n in range (2, x//2 + 1):
            if x%n == 0:
                f = False
                break
        if f == True:
            print(x)
            break
    if f == False:
        print ('0')
else: print('0')
